#include <iostream>
#include <stdio.h>
#include <stdlib.h>

#include <openCV/highgui.h>
#include <openCV/cv.h>
#include "filtre.hpp"
#include "regionGrowing.hpp"


int main (int argc, char* argv[])
{
  IplImage* img = NULL; 
  IplImage* img2 = NULL; 
  
  const char* window_title = "analyse image";

 /* if (argc < 2)
  {
    fprintf (stderr, "usage: %s IMAGE\n", argv[0]);
    return EXIT_FAILURE;
  }*/
  //img = cvLoadImage("../image/bin.jpg", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/B.JPG", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/B1.JPG", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/balls0.jpg", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/bally_0.jpg", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/cake_0.JPG", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/purple_2_bw.jpg", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("../image/rose_2_bw.jpg", CV_LOAD_IMAGE_UNCHANGED);
  img = cvLoadImage("image2.jpg", CV_LOAD_IMAGE_UNCHANGED);
  //img = cvLoadImage("image.jpg", CV_LOAD_IMAGE_UNCHANGED);
  if (img == NULL)
  {
    fprintf (stderr, "couldn't open image file: %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  
  
  

  cvNamedWindow (window_title, CV_WINDOW_AUTOSIZE);
  cvShowImage (window_title, img);
  cvNamedWindow ("original", CV_WINDOW_AUTOSIZE);
  cvShowImage ("original", img);
  cvWaitKey(0);

  //img2=cvCreateImage(cvSize(img->width,img->height),img->depth,3);
  //cvSmooth(img, img2,CV_GAUSSIAN,19,0);
  img2=filtreGaussien(img,3);
  cvShowImage (window_title, img2);
  cvWaitKey(0);

  RegionGrowing rg(img2);

  rg.poseGerme();
  
  IplImage* img3;
  img3=rg.rendu();
  cvShowImage (window_title, img3);
  cvWaitKey(0);
  
  rg.croissance();
  img3=rg.rendu();
  cvShowImage (window_title, img3);
  cvWaitKey(0);
  
  rg.fusion();
  img3=rg.rendu();
  cvShowImage (window_title, img3);
  cvWaitKey(0);
  
  IplImage* img4=rg.frontiere(img3);
  cvShowImage (window_title, img4);
  cvWaitKey(0);
  
  cvDestroyAllWindows();
  cvReleaseImage(&img);


  return 0;
}
